﻿using NuMvvm.Commands;
using NuMvvm.Services;
using NuMvvm.Testing.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Todo.Tests.Mocks;
using Todo.ViewModels;
using NUnit.Framework;

namespace Todo.Tests
{
    public class ItemViewModelTest
    {
        [TestCase]
        public async Task CreateNewItemAndSave()
         {
            Services.IDataService dataService = new MockDataService();
            IDialogService dialogService = new MockDialogService();
            INavigationService navigationService = new MockNavigationService();

            int itemId = 0;

            var itemViewModel = new ItemViewModel(
                dataService, 
                dialogService, 
                navigationService);

            await itemViewModel.Initialize();

            Assert.AreEqual(itemViewModel.Id, itemId);

            var okCommand = itemViewModel.OkCommand as AsyncDelegateCommand;
            await okCommand.ExecuteAsync();
        }

        [TestCase]
        public async Task LoadExistingItemEditAndSave()
        {
            Services.IDataService dataService = new MockDataService();
            IDialogService dialogService = new MockDialogService();
            INavigationService navigationService = new MockNavigationService();

            int itemId = 2;

            var itemViewModel = new ItemViewModel(
                dataService, 
                dialogService, 
                navigationService);

            await itemViewModel.Initialize(itemId);

            Assert.AreEqual(itemViewModel.Id, itemId);

            var okCommand = itemViewModel.OkCommand as AsyncDelegateCommand;
            await okCommand.ExecuteAsync();
        }
    }
}